import os
import sys
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2.QtCore import *


class Name(QWidget):  # 创建一个QWidget子类
    def __init__(self):
        super(Name, self).__init__()
        self.lay = QHBoxLayout()  # 创建一个主布局（下面可以加元素或者小布局）
        self.setWindowTitle('窗口标题')  # 设置标题

        self.left = QVBoxLayout()  # 创建一个小布局
        self.left.setAlignment(Qt.AlignTop)  # 布局里面的排列方式（Qt.AlignTop）
        self.left.setContentsMargins(0, 20, 0, 0)  # 布局边缘（参数顺序为：（左，上，右，下））
        self.left.setSpacing(15)  # 布局间隙（组件跟组件之间的间隙）

        self.name0 = QLabel('Rig')  # 创建组件标签
        self.name1 = QLabel('Ani')
        self.name2 = QLabel('Mod')
        self.name3 = QLabel('Re')
        self.name4 = QLabel('Mp')

        self.cb = QCheckBox('这是一个复选框')
        self.cb.clicked.connect(self.a)

        self.rb = QRadioButton('这是一个单选按钮')
        self.rb.clicked.connect(self.a)

        self.row = QLineEdit()
        self.button = QPushButton('测试')
        self.button1 = QPushButton('测试2')
        self.button.clicked.connect(self.rig)
        self.button1.clicked.connect(self.text)

        self.text_edit = QTextEdit()
        self.text_edit.setText('111111111111')

        self.tb = QTextBrowser()
        self.tb.setText('2222222222222222222')

        self.left.addWidget(self.cb)
        self.left.addWidget(self.rb)

        self.left.addWidget(self.name0)  # 添加子组件
        self.left.addWidget(self.name1)
        self.left.addWidget(self.name2)
        self.left.addWidget(self.name3)
        self.left.addWidget(self.name4)

        self.left.addWidget(self.button)
        self.left.addWidget(self.button1)
        self.left.addWidget(self.text_edit)
        self.left.addWidget(self.row)
        self.left.addWidget(self.tb)



        self.right = QVBoxLayout()  # 创建一个小布局
        self.right.setAlignment(Qt.AlignTop)  # 布局里面的排列方式（Qt.AlignTop）
        self.name_v0 = QLabel('Rg')  # 创建标签组件
        self.name_v1 = QLabel('Ai')
        self.name_v2 = QLabel('Md')
        self.name_v3 = QLabel('MM')



        self.right.addWidget(self.name_v0)  # 添加子组件
        self.right.addWidget(self.name_v1)
        self.right.addWidget(self.name_v2)
        self.right.addWidget(self.name_v3)
        # self.right.addWidget(self.name_v1)

        self.lay.addLayout(self.left)  # 把小布局添加到主布局里
        self.lay.addLayout(self.right)

        self.setLayout(self.lay)  # 把主布局(self.lay)给该窗口

    def rig(self):
        # name = self.name0.text()
        # text = self.row.text()
        # self.row.setText('aaaaa')
        #
        # name1 = self.text_edit.toPlainText()
        # # self.text_edit.setText('asdfasgsg')
        #
        # name_cb = self.cb.checkState()
        # print(name_cb)
        # name_isc = self.cb.isChecked()
        # print(name_isc)
        # if name_isc == False:
        #     aa = self.text_edit.toPlainText()
        #     self.tb.setText(aa)
        # else:
        #     t_text = self.cb.text()
        #     self.tb.setText(t_text)
        # os.startfile(os.path.abspath(''))


        # Qt.Checked
        # if name_cb == Qt.Unchecked: #
        #     print('True')
        # else:
        #     print('False')

        dir_path = QFileDialog.getExistingDirectory(self, '选择文件夹')
        print(dir_path)
        self.row.setText(dir_path)


    def text(self):
        # row_text = self.row.text()
        # self.name0.setText(row_text)
        # t = self.text_edit.toPlainText()
        # r = self.row.text()
        # path = os.path.join(r,'test.txt')
        # with open(path, 'w', encoding='utf8') as w:
        #     w.write(t)
        # os.startfile(r)

        # openfile_name = QFileDialog.getOpenFileName(self, '选择文件', '', 'files(*)')
        # print(openfile_name)
        # os.startfile(openfile_name[0])

        fileName = QFileDialog.getSaveFileName(None, "选择保存路径", ".", "Maya(*.ma)")
        print(fileName)
    def a(self, c):
        print(c)



if __name__ == '__main__':
    app = QApplication(sys.argv)  # 实例一个qt的应用程序，把脚本的所有参数传进去（maya不需要这句话。因为maya窗口就是一个应用程序）
    name = Name()  # 实例化类
    name.show()  # 显示窗口
    app.exec_()  # 执行窗口
    sys.exit()  # 程序退出
    # sys.exit(app.exec_())  #执行窗口并退出程序